package com.yan.shopping.domain;

import com.yan.shopping.Expection.NameExpection;
import com.yan.shopping.Expection.PassWordExpection;
import com.yan.shopping.dao.DateProduct;
import com.yan.shopping.service.ShoppingServicesimpl;
import org.w3c.dom.ls.LSOutput;

import java.util.Scanner;

public class User {

    public static final Scanner INPUT = new Scanner(System.in);
    public static final ShoppingServicesimpl check = new ShoppingServicesimpl();
    private StringBuffer name;
    private StringBuffer passWord;
    private StringBuffer otherName;
    private Integer age;

    public User(StringBuffer name, StringBuffer passWord, StringBuffer otherName, Integer age) {
        Integer checking = check.Checking(name);
        if(checking == -1){
            try {
                throw new NameExpection();
            } catch (NameExpection nameExpection) {
                System.out.println("输入的用户名重复");
                System.out.println("请重新输入");
                name.delete(0 , name.length());
                name.append(INPUT.next());
            }
        }
        if(passWord.length() < 6){
            try {
                throw new PassWordExpection();
            } catch (PassWordExpection passWordExpection) {
                System.out.println("密码不能小于6位");
                System.out.println("请重新输入");
                name.delete(0 , name.length());
                name.append(INPUT.next());
            }
        }
        this.name = name;
        this.passWord = passWord;
        this.otherName = otherName;
        this.age = age;
    }

    public User() {

    }

    public StringBuffer getName() {
        return name;
    }

    public void setName(StringBuffer name) {
        Integer checking = check.Checking(name);
        if(checking != -1){
            try {
                throw new NameExpection();
            } catch (NameExpection nameExpection) {
                System.out.println("输入的用户名重复");
                System.out.println("请重新输入");
                name.append(INPUT.next());
            }
        }
        this.name = name;
    }

    public StringBuffer getPassWord() {
        return passWord;
    }

    public void setPassWord(StringBuffer passWord) {
        this.passWord = passWord;
    }

    public StringBuffer getOtherName() {
        return otherName;
    }

    public void setOtherName(StringBuffer otherName) {
        this.otherName = otherName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        if (passWord != null ? !passWord.equals(user.passWord) : user.passWord != null) return false;
        if (otherName != null ? !otherName.equals(user.otherName) : user.otherName != null) return false;
        return age != null ? age.equals(user.age) : user.age == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (passWord != null ? passWord.hashCode() : 0);
        result = 31 * result + (otherName != null ? otherName.hashCode() : 0);
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return name +"\t\t" + passWord +"\t\t" + otherName +"\t\t" + age;
    }


}
